package asteroids.model.programs.expressions.ComposedExpressions.BinaryExpressions;

import asteroids.model.programs.expressions.BasicExpression;
import asteroids.model.programs.expressions.Expression;
import asteroids.model.programs.expressions.BasicExpressions.BooleanLiteral;
import asteroids.model.programs.expressions.ComposedExpressions.BinaryExpression;
import asteroids.model.programs.types.Type;

public class And extends BinaryExpression {
	
	/**
	 * Initialize the And object
	 * 
	 * @param leftExp
	 * 			The left operand of this expression
	 * @param rightExp
	 * 			The right operand of this expression
	 * @effect ...
	 * 			|super(leftExp, rigthExp)
	 */
	public And(Expression leftExp, Expression rightExp, int line, int column){
		super(leftExp, rightExp, line, column);
	}
	
	/**
	 * Returns the symbol for this Expression, namely &&
	 * 
	 * @return ...
	 * 			| return "&&"
	 */
	@Override
	public String getOperatorSymbol() {
		return "&&";
	}

	/**
	 * Returns the BasicExpression of type BooleanLiteral with the result of the expression
	 * 
	 * @return ...
	 * 			| result.equals(new BooleanLiteral(getLeftOperand().getResult().getValue()&&
	 * 												getRightOperand().getResult.getValue())
	 */
	@Override
	public BasicExpression getResult() {
		boolean leftValue = ((BooleanLiteral)getLeftOperand().getResult()).getValue();
		boolean rightValue = ((BooleanLiteral)getRightOperand().getResult()).getValue();
		boolean resultValue = leftValue && rightValue;
		BasicExpression result = new BooleanLiteral(resultValue, getLine(), getColumn());
		return result;
	}
	
	@Override
	public Type getType(){
		return Type.BOOLEAN;
	}
	
	@Override 
	public Type[] getOperandType(){
		return new Type[]{Type.BOOLEAN};
	}

}
